https://blog.csdn.net/ourkix/article/details/103471931
#通过dpkg -l查看所安装的opencv库 
dpkg -l | grep -i opencv 
#看到相关的opencv就可以用apt-get来卸载了
#移除相关libopencv库 
sudo apt-get remove libopencv*

wget -O opencv.zip https://github.com/opencv/opencv/archive/refs/tags/4.7.0.zip
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/refs/tags/4.7.0.zip
unzip opencv.zip
unzip opencv_contrib.zip

cd opencv-4.7.0
mkdir build
cd build

whereis cuda
which python

cmake 
-D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local \
-D BUILD_opencv_world=ON -D BUILD_EXAMPLES=OFF\
-D BUILD_opencv_python2=OFF -D BUILD_opencv_python3=ON \
-D WITH_FFMPEG=OFF -D WITH_TBB=ON \
-D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-11.4 \
-D ENABLE_FAST_MATH=ON -D CUDA_FAST_MATH=ON \
-D WITH_CUDA=ON -D BUILD_opencv_cudacodec=ON -D WITH_CUDNN=ON \
-D OPENCV_DNN_CUDA=ON -D CUDNN_VERSION=8.0  \
-D CUDA_ARCH_BIN=7.2 -D CUDA_ARCH_PTX=7.2 \
-D WITH_LIBV4L=ON -D WITH_CUBLAS=1 \
-D WITH_V4L=ON -D WITH_QT=OFF -D WITH_OPENGL=ON -D WITH_GSTREAMER=OFF \
-D OPENCV_GENERATE_PKGCONFIG=ON -D OPENCV_PC_FILE_NAME=opencv.pc \
-D OPENCV_ENABLE_NONFREE=ON \
-D OPENCV_PYTHON3_INSTALL_PATH=/home/admin-nx/.local/lib/python3.8/site-packages \
-D PYTHON_EXECUTABLE=/usr/bin/python3.8 \
-D OPENCV_EXTRA_MODULES_PATH=/home/admin-nx/opencv4.5.4/opencv_contrib-4.5.4/modules \
-D ENABLE_NEON=ON -D WITH_CAROTENE=ON \
-D BUILD_TESTS=OFF \
-D BUILD_PERF_TESTS=OFF -D INSTALL_PYTHON_EXAMPLES=OFF -D INSTALL_C_EXAMPLES=OFF   ..

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local \
-D BUILD_opencv_world=ON -D BUILD_EXAMPLES=OFF \
-D WITH_FFMPEG=OFF -D WITH_TBB=ON \
-D WITH_V4L=ON -D WITH_QT=OFF -D WITH_OPENGL=ON -D WITH_GSTREAMER=OFF \
-D OPENCV_GENERATE_PKGCONFIG=ON -D OPENCV_PC_FILE_NAME=opencv.pc \
-D OPENCV_ENABLE_NONFREE=ON \
-D OPENCV_EXTRA_MODULES_PATH=/home/server/opencv-4.7.0/opencv_contrib-4.7.0/modules \
-D BUILD_TESTS=OFF \
-D BUILD_PERF_TESTS=OFF -D INSTALL_PYTHON_EXAMPLES=OFF -D INSTALL_C_EXAMPLES=OFF   ..


 
readonly CMAKEFLAGS="
	-D CMAKE_BUILD_TYPE=RELEASE
	-D CMAKE_INSTALL_PREFIX=${PREFIX}
    -D BUILD_opencv_world=ON
	-D BUILD_EXAMPLES=OFF
	-D BUILD_opencv_python2=OFF
	-D BUILD_opencv_python3=ON
	-D WITH_FFMPEG=OFF
	-D WITH_TBB=ON
    -D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-11.4 
	-D CUDA_FAST_MATH=ON
	-D ENABLE_FAST_MATH=ON
	-D WITH_CUDA=ON
	-D WITH_CUDNN=ON
	-D OPENCV_DNN_CUDA=ON
	-D CUDNN_VERSION='8.0'
	-D CUDA_ARCH_BIN=7.2
    -D CUDA_ARCH_PTX=7.2
	-D WITH_LIBV4L=ON
	-D WITH_V4L=ON
	-D WITH_CUBLAS=ON
	-D OPENCV_ENABLE_NONFREE=ON
	-D OPENCV_EXTRA_MODULES_PATH=$OPENCV_SOURCE_DIR/opencv_contrib-$OPENCV_VERSION/modules
	-D OPENCV_PYTHON3_INSTALL_PATH=/home/admin-nx/.local/lib/python3.8/site-packages 
	-D PYTHON_EXECUTABLE=/usr/bin/python3.8 
	-D OPENCV_GENERATE_PKGCONFIG=ON
	-D OPENCV_PC_FILE_NAME=opencv.pc
	-D WITH_GSTREAMER=OFF
	-D WITH_GSTREAMER_0_10=OFF
	-D WITH_OPENGL=ON
    -D ENABLE_NEON=ON 
	-D WITH_CAROTENE=ON
	-D CPACK_BINARY_DEB=OFF
	-D BUILD_PERF_TESTS=OFF
	-D BUILD_TESTS=OFF
	-D INSTALL_PYTHON_EXAMPLES=OFF
	-D INSTALL_C_EXAMPLES=OFF	
	"